<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cap.bean.Admin" %>
<%@ page import="cap.bean.User" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%
    Admin admin = (Admin)request.getSession().getAttribute("admin");//管理员信息
    List<User> uList=(List<User>)request.getAttribute("uList");//用户列表
    String succDeleMsg = (String)request.getSession().getAttribute("succDeleMsg");	//禁用用户消息
    String errorDeleMsg = (String)request.getSession().getAttribute("errorDeleMsg");
    String succActMsg = (String)request.getSession().getAttribute("succActMsg");	//启用用户消息
    String errorActMsg = (String)request.getSession().getAttribute("errorActMsg");
    int curPage = (Integer)request.getAttribute("curPage");
    int totalPages = (Integer)request.getAttribute("totalPages");
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>博客</title>
    <link href="<%=basePath%>bootstrap/css/blog-home.css"/>
    <link href="<%=basePath%>bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="<%=basePath%>bootstrap/js/jquery-2.1.1.js"></script>
</head>
  <c:if test="${null!=admin}">
<div class="container">
    <!-- Sidebar -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="<%=basePath %>admin?method=index">博客管理系统</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-ex1-collapse">
            <ul class="nav navbar-nav side-nav">
                <li><a href="<%=basePath %>admin?method=index"><i class="glyphicon glyphicon-dashboard"></i> 控制面板</a></li>
                <li class="active"><a href="<%=basePath %>admin?method=useradmin"><i class="glyphicon glyphicon-cog"></i> 用户管理</a></li>
                <li><a href="<%=basePath %>admin?method=SysArticalAdmin"><i class="glyphicon glyphicon-cog"></i> 文章管理</a></li>
                <li><a href="<%=basePath %>admin?method=SysCategoryAdmin"><i class="glyphicon glyphicon-edit"></i> 分类管理</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right navbar-user">
                <li><a href="#"><i class="glyphicon glyphicon-user"></i>${admin.userName}</a></li>
            <li><a href="<%=basePath%>admin?method=logout"><i class="glyphicon glyphicon-off"></i> 登出</a></li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </nav>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-md-12">
                <br>
                <ol class="breadcrumb">
                    <li><a href="<%=basePath%>admin/admin.jsp"><i class="glyphicon glyphicon-dashboard"></i> 控制面板</a></li>
                    <li class="active"><i class="glyphicon glyphicon-cog"></i> 用户管理</li>
                </ol>
                <%-- 禁用账户结果提示消息 --%>
                <c:if test="${null != succDeleMsg}">
                <div class="row">
                    <div class="col-md-12">
                        <div class="alert alert-success">${succDeleMsg}</div>
                    </div>
                </div>
                <%
                        request.getSession().removeAttribute("succDeleMsg");
                %>
                </c:if>
                <c:if test="${null != errorDeleMsg}">
                <div class="row">
                    <div class="col-md-12">
                        <div class="alert alert-danger">${errorDeleMsg}</div>
                    </div>
                </div>
                <%
                        request.getSession().removeAttribute("errorDeleMsg");
                %>
                </c:if>
                <%-- 激活账户结果提示消息 --%>
                <c:if test="${ null != succActMsg}">
                <div class="row">
                    <div class="col-md-12">
                        <div class="alert alert-success">${succActMsg}</div>
                    </div>
                </div>
                <%
                        request.getSession().removeAttribute("succActMsg");
                %>
                </c:if>
                <c:if test="${null != errorActMsg}">
                <div class="row">
                    <div class="col-md-12">
                        <div class="alert alert-error">${errorActMsg}</div>
                    </div>
                </div>
                <%
                        request.getSession().removeAttribute("errorActMsg");
                %>
                </c:if>
                <div class="row">
                    <div class="col-md-12">
                        <div class="table-responsive">
                            <table class="table table-hover tablesorter">
                                <thead>
                                <tr>
                                    <th>用户名</th>
                                    <th>是否申请博客</th>
                                    <th>邮箱地址</th>
                                    <th>当前状态</th>
                                    <th>操作</th>
                                    <th>查看用户信息</th>
                                </tr>
                                </thead>
                                <tbody>
                                <%
                                    if(uList != null){
                                        for(User u : uList){
                                            String deleUrl = basePath + "admin?method=deleteuser&uId=" + u.getId(); //禁用账号
                                            String actUrl = basePath + "admin?method=activeuser&uId=" + u.getId(); //激活账号
                                            String detailUrl = basePath + "admin?method=userprofile&uId=" + u.getId() ;//详细信息
                                %>
                                <tr>
                                    <td><%=u.getUserName() %></td>
                                    <td>
                                        <% if (u.getIsApplied() == 1) { %>
                                        <span class="label label-success">已申请</span><!--可用-->
                                        <% } else { %>
                                        <span class="label label-danger">未申请</span>
                                        <% }  %>
                                    </td>
                                    <td><%=u.getEmail() %></td>
                                    <td>
                                        <% if (u.getIsDelete() == 0) { %>
                                        <span class="label label-success">可用</span>
                                        <% } else { %>
                                        <span class="label label-danger">不可用</span><!--不可用-->
                                        <% } %>
                                    </td>
                                    <td>
                                        <% if (u.getIsDelete() == 1) { %>

                                        <a onClick="act('<%=actUrl %>')" class="btn btn-success btn-xs"> 启用账号</a>
                                        <% } else { %>
                                        <a onClick="dele('<%=deleUrl %>')" class="btn btn-danger btn-xs"> 禁用账号</a>
                                        <% } %>
                                    </td>
                                    <td>
                                        <% if (u.getIsProfile() == 1) { %>
                                        <a href="<%=detailUrl %>" class="btn btn-primary btn-xs">详细信息</a>
                                        <% } else { %>
                                        <a class="btn btn-warning btn-xs">尚未更新资料</a><!--警示-->
                                        <% } %>
                                    </td>
                                </tr>
                                <%
                                    }
                                }else{%>
                                <%="获取用户资料失败"%>
                                <%} %>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <!-- pager -->
                <ul class="pager">
                    <% if (curPage > 1) { %>
                    <li class="previous"><a href="<%=basePath%>admin?method=useradmin&curPage=<%=(curPage-1)%>">&larr; 上一页</a></li>
                    <% } %>

                    <% if (curPage < totalPages) { %>
                    <li class="next"><a href="<%=basePath%>admin?method=useradmin&curPage=<%=(curPage+1)%>">下一页  &rarr;</a></li>
                    <% } %>
                </ul>

            </div>
        </div><!-- /.row -->
    </div><!-- /#page-wrapper -->
</div>
  </c:if>
<c:if test="${null==admin}">
<%-- 404 page --%>
<jsp:include page="404.jsp"></jsp:include>
</c:if>
<script type="text/javascript">
    function dele(deleUrl) {
        if (confirm("你确定要禁用该用户吗？")) {
            location.href = deleUrl;
        }
    }
    function act(actUrl) {
        if (confirm("你确定要激活该用户吗？")) {
            location.href = actUrl;
        }
    }
</script>
<div><audio autoplay="autoplay" loop="true"><source src="music/1.mp3"></audio></div>
</body>
</html>

